const app = getApp();
import { getPointRecordList } from '../../utils/requestApi.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: app.data.imgurl,
    tabBar: ['明细', '积分收入', '积分支出'],
    integral: 0,  //积分
    activeItem: 0,
    page: 1,
    listData:[],
    showEmpty: false, //显示空的页面
    currentPoints: 0, //当前积分
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initData();
  },

  onShow: function (){
    
  },
   
  //选择tab
  selectTab:function(e){
    this.setData({
      activeItem: e.detail.index,
      page: 1,
      listData: []
    })
    this.initData()
  },

  initData(){
    let { page, activeItem, listData, currentPoints, showEmpty } = this.data;
    getPointRecordList({
      pageIndex: page,
      pageSize: 10,
      PointType: activeItem
    }).then(res =>{
      if (res.data.Result.PointList.length != 0) page++;
      else this.setData({ showEmpty: true })
      this.setData({ listData: [...listData, ...res.data.Result.PointList], currentPoints: res.data.Result.CurrentPoints, page })
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.initData();    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }  

})